﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.IO;

/// <summary>
/// Summary description for NhanVien
/// </summary>
public class NhanVien
{
	public NhanVien()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    DataConnection data = new DataConnection();
    public DataTable LayDSNhanVien()
    {
        string sql = "select * from NhanVien";
        return data.GetData(sql);
    }


    public DataTable SuaNV(int ma,string hoten, string TenDN, string MatKhau,bool gioitinh, string ngaysinh, string diachi, string Email, string dienthoai, string CMND)
    {
        SqlParameter pma = new SqlParameter("@ma", ma);
        SqlParameter pho =new SqlParameter("@hoten", hoten);
        SqlParameter pTDN = new SqlParameter("@tenDN", TenDN);
        SqlParameter pMK = new SqlParameter("@matkhau", MatKhau);
       SqlParameter pgioitinh = new  SqlParameter("@gioitinh", gioitinh);
        SqlParameter pngaysinh = new SqlParameter("@ngaysinh", ngaysinh);
        SqlParameter pdiachi = new SqlParameter("@diachi", diachi);
        SqlParameter pEmail = new  SqlParameter("@email", Email);
        SqlParameter pdienthoai = new SqlParameter("@dienthoai", dienthoai);
        SqlParameter pCMND = new SqlParameter("@CMND", CMND);
        string sql = "update NhanVien set HoTen=@hoten,TenDN=@tenDN,MatKhau=@matKhau,Gioitinh=@gioitinh,Ngaysinh=@ngaysinh,Diachi=@diachi,Email=@email,Dienthoai=@dienthoai,CMND=@cmnd where MaNV=@ma";
        return data.GetData(sql,pma, pho,pTDN,pMK, pgioitinh, pngaysinh, pdiachi, pdienthoai, pEmail, pCMND);
    }

    public DataTable InsertNV(string hoten,string tendn,string matkau, bool gioitinh, string ngaysinh, string diachi, string dienthoai, string email, string chungminh)
    {
        string sql = "insert into NhanVien (HoTen,TenDN,MatKhau,GioiTinh,NgaySinh,DiaChi,DienThoai,Email,CMND) values (@HoTen,@TenDN,@MatKhau,@GioiTinh,@NgaySinh,@DiaChi,@DienThoai,@Email,@CMND)";
        SqlParameter p1 = new SqlParameter("@HoTen", hoten);
        SqlParameter p8 = new SqlParameter("@TenDN", tendn);
        SqlParameter p9 = new SqlParameter("@MatKhau", matkau);
        SqlParameter p2 = new SqlParameter("@GioiTinh", gioitinh);
        SqlParameter p3 = new SqlParameter("@NgaySinh", ngaysinh);
        SqlParameter p4 = new SqlParameter("@DiaChi", diachi);
        SqlParameter p5 = new SqlParameter("@DienThoai", dienthoai);
        SqlParameter p6 = new SqlParameter("@Email", email);
        SqlParameter p7 = new SqlParameter("@CMND",chungminh);
        return data.GetData(sql, p1, p8,p9, p2, p3, p4, p5, p6, p7);
    }
    public DataTable XoaNV(int ma)
    {
        string sql = "delete NhanVien where MaNV=@MaNV";
        SqlParameter manv = new SqlParameter("@MaNV", ma);
        return data.GetData(sql, manv);
    }

    public DataTable TimNV(string ten, bool gioitinh)
    {
            string sql="select MaNV,HoTen,TenDN,MatKhau,GioiTinh,NgaySinh,DiaChi,Email,DienThoai,CMND from NhanVien where 1=1";
            if (ten != null)
                sql = sql + " and HoTen like '%'+@ten+'%'";
            if (gioitinh != null)
                sql = sql + " and GioiTinh=@gioitinh";
        SqlParameter p = new SqlParameter("@ten", ten);
        SqlParameter p1 = new SqlParameter("@gioitinh", gioitinh);
        return data.GetData(sql, p, p1);
    }

}
